package warpper;

public class IntegerDemo1 {
    public static void main(String[] args) {
        //基本类型转换为包装类
        int a =128;
//        Integer i1 = new Integer(a);
//        Integer i2 = new Integer(a);
        //java推荐将基本类型转换为包装类时,使用包装类的valueof方法
        Integer i1 = Integer.valueOf(a);
        Integer i2 =Integer.valueOf(a);

        System.out.println("i1:"+i1);
        System.out.println("i2:"+i2);
        System.out.println(i1==i2);//false
        System.out.println(i1.equals(i2));//true

        double dou =3.14;
        Double d1 = Double.valueOf(dou);
        Double d2 = Double.valueOf(dou);
        System.out.println(d2==d1);//false
        System.out.println(d2.equals(d1));//true

        //包装类转换为基本类型
        int i =i1.intValue();
        System.out.println(i);
        long l = i1.longValue();
        System.out.println(l);//long l =128;
        byte b =i1.byteValue();//注意溢出问题
        System.out.println(b);//-128

        i = d1.intValue();//double转换为int会丢失精度
        System.out.println(i);
    }

}
